class NumArray:

    def __init__(self, nums):
        self.nums = nums
        self.left = [0] * (len(nums) + 1)
        self.initLeftNum = 1

    def update(self, i: int, val: int) -> None:
        self.initLeftNum = min(self.initLeftNum, i+1)
        self.nums[i] = val

    def sumRange(self, i: int, j: int) -> int:
        if self.initLeftNum < len(self.nums) + 1:
            self.initLeft()
        return self.left[j+1] - self.left[i]

    def initLeft(self):
        for i in range(self.initLeftNum, len(self.nums)+1):
            if i == 0:
                self.left[i] = self.nums[i]
            else:
                self.left[i] = self.left[i - 1] + self.nums[i-1]
        self.initLeftNum = len(self.nums)+1

if __name__ == '__main__':
    so = NumArray([-2,0,3,-5,2,-1])
    print(so.sumRange(1,2))
